package znyl.nursing.service.impl;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.data.redis.core.RedisTemplate;
import znyl.common.core.redis.RedisCache;
import znyl.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import znyl.nursing.mapper.RoomMapper;
import znyl.nursing.domain.Room;
import znyl.nursing.service.IRoomService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import znyl.nursing.vo.RoomVo;

import java.util.Arrays;

/**
 * 房间Service业务层处理
 * 
 * @author 睢高浩
 * @date 2025-11-05
 */
@Service
public class RoomServiceImpl extends ServiceImpl<RoomMapper, Room> implements IRoomService
{
    @Autowired
    private RoomMapper roomMapper;
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    private static final String KEY = "Room:";

    /**
     * 查询房间
     * 
     * @param id 房间主键
     * @return 房间
     */
    @Override
    public Room selectRoomById(Long id)
    {
        return getById(id);
    }

    /**
     * 查询房间列表
     * 
     * @param room 房间
     * @return 房间
     */
    @Override
    public List<Room> selectRoomList(Room room)
    {
        return roomMapper.selectRoomList(room);
    }

    /**
     * 新增房间
     * 
     * @param room 房间
     * @return 结果
     */
    @Override
    public int insertRoom(Room room)
    {
        return roomMapper.insertRoom(room);
    }

    /**
     * 修改房间
     * 
     * @param room 房间
     * @return 结果
     */
    @Override
    public int updateRoom(Room room)
    {
        return updateById(room) == true ? 1 : 0;
    }

    /**
     * 批量删除房间
     * 
     * @param ids 需要删除的房间主键
     * @return 结果
     */
    @Override
    public int deleteRoomByIds(Long[] ids)
    {
        return removeByIds(Arrays.asList(ids)) == true ? 1 : 0;
    }

    /**
     * 删除房间信息
     * 
     * @param id 房间主键
     * @return 结果
     */
    @Override
    public int deleteRoomById(Long id)
    {
        return removeById(id) == true ? 1 : 0;
    }

    @Override
    public RoomVo getRoomById(Long id) {
        //从缓存中获取数据
        RoomVo roomVo = (RoomVo) redisTemplate.opsForValue().get(KEY);
        return roomMapper.getRoomById(id);
    }
}
